﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Decisions.HL7.Parser
{
    public class PropertyDescriptor
    {
        public Type DataType { get; set; }
        public string Name { get; set; }
        public bool  ReadOnly { get; set; }

        public PropertyInfo InternalMemberInfo { get; set; }

        public PropertyDescriptor()
        {

        }

        public PropertyDescriptor(MemberInfo mi)
        {
            if (mi is PropertyInfo)
            {
                InternalMemberInfo = (PropertyInfo)mi;


                this.Name = mi.Name;
                PropertyInfo property = (PropertyInfo)mi;
                this.DataType = property.PropertyType;
                
                ReadOnly = !(property.GetSetMethod() != null && property.GetSetMethod().IsPublic);
                
            }

        }


        internal void SetValue(DataTypes.AbstractDataType abstractDataType, object valueToSet)
        {
            ((PropertyInfo)InternalMemberInfo).SetValue(abstractDataType, valueToSet);
        }
    }
}
